import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App.vue'
import router from './router/index.js'
import axios from 'axios'
import qs from 'qs'
import 'font-awesome/css/font-awesome.css'

import {Message} from 'element-ui'

Vue.use(ElementUI)
Vue.prototype.$axios = axios
Vue.prototype.$qs = qs

//注册api插件
import {getRequest} from "./utils/api.js"
import {postRequest} from "./utils/api.js"
Vue.prototype.$getRequest = getRequest;
Vue.prototype.$postRequest = postRequest;

//引入mock
require('./mock/index.js')

//引入mavon-editor
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
Vue.use(mavonEditor)

//引入ECharts
import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts;

router.beforeEach((to, from, next) => {
	document.body.style.background = '#2d3a4b';
	if (to.path == '/') {
		next();
	} else {
		let user = sessionStorage.getItem('loginer');
		if (user != null) {
			document.body.style.background = '#ffffff';
			next();
		} else {
			Message.warning({message:'请先登录'});
			next('/');
		}
	}
})

new Vue({
	el: '#app',
	render: h => h(App),
	router
})
